export default class Proxy {
  constructor(el, eventType) {
    this.$el = el;
    this.$el.addEventListener(eventType, (event) => {
      let action = event.target.dataset.action;
      this.$event = event;
      if (this[action]) {
        this[action].call(this, event);
      }
    });
  }

  // 关闭指定tab
  closeCurrent(event) {
    console.log(event.target.dataset);
    let { name } = event.target.dataset;
    document.getElementById(name).remove();
    event.target.parentNode.remove();
  }

  // tab切换
  toggle(event) {
    let items = this.$el.querySelectorAll(".body div");
    let target = event.target;

    Array.from(items).map((item) => {
      if (item.id == target.dataset.name) {
        item.style.display = "block";
      } else {
        item.style.display = "none";
      }
    });
  }

  // 关闭整个 tab
  close() {
    this.$el.style.display = "none";
  }
}
